package com.sh.produce;

import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.jms.Destination;
import javax.jms.Queue;
import java.util.UUID;

/**
 * @ClassName QueueProduce
 * @Description TODO
 * @Author yaoqiang
 * @Date 2020/10/27 13:41
 * @Version 1.0
 */
@Component
public class QueueProduce {
    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private Queue queue;

    public void produceMessage(){
        Destination destination = new ActiveMQTopic(": boot-activemq-queue2");
        jmsMessagingTemplate.convertAndSend( destination ,"*****scheduled*****"+ UUID.randomUUID().toString().substring(0,6));
        System.out.println("produceMessageScheduled2 ok");
    }

    @Scheduled(fixedDelay = 3000)
    public void produceMessageScheduled(){
        jmsMessagingTemplate.convertAndSend( queue ,"*****scheduled*****"+ UUID.randomUUID().toString().substring(0,6));

        System.out.println("produceMessageScheduled ok");
    }
}
